<?php

header("Content-type: text/html; charset=utf-8");

$con = mysql_connect("localhost","root","");

if (!$con) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("my-english", $con);
mysql_query('SET NAMES utf8');

$res = mysql_query("select * from ru_words where relation in ( select id from en_words where word like '".$_POST['word']."' )");

if($res && mysql_num_rows($res)>0) {
	print "{";
	for ($i=0; $i<mysql_num_rows($res); ++$i) {
		$row = mysql_fetch_row($res);
		if ($i==0 || $row[3]!=$type)	{
			$type = $row[3];
			if ($i!=0) print "\", "; 
			print "\"$type\": \"";
		}
		else print "; ";
		$id = $row[0];
		$tran = $row[1];
		print $tran."[".$id."]";
	}
	print "\"}";
}
?> 